/*
 * File:   GenericAdapterTest.cpp
 * Author: Guilherme Monteiro
 *
 */

#include "GenericAdapterTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(GenericAdapterTest);

GenericAdapterTest::GenericAdapterTest() {
    string path1 = "/books/caracterizacao/baixa_resolucao/image278.png"; // taxes = 1.0
    string path2 = "/books/estatisticas/baixa_resolucao/image49.png";    // taxes != 1.0
    
    GenericModel* model1 = new Model1();
    
//    MetaInfo* metainfo1 = new TranscriberMetaInfo(path1, model1);
    MetaInfo* metainfo2 = new TranscriberMetaInfo(path2, model1);
    
//    genericAdapter1 = new GenericAdapter(HIGH_2_LOW, metainfo1);
//    genericAdapter2 = new GenericAdapter(LOW_2_HIGH, metainfo1);
    
    genericAdapter3 = new GenericAdapter(HIGH_2_LOW, metainfo2);
//    genericAdapter4 = new GenericAdapter(LOW_2_HIGH, metainfo2);
    
    Cell cell1(cvPoint(0,0), cvPoint(5,5));
    Cell cell2(cvPoint(5,0), cvPoint(10,5));
    Cell cell3(cvPoint(0,5), cvPoint(5,10));
    Cell cell4(cvPoint(5,5), cvPoint(10,10));
    
    cells.push_back(cell1);
    cells.push_back(cell2);
    cells.push_back(cell3);
    cells.push_back(cell4);
    
    h_2_l_hor = 0.2942;
    h_2_l_vert = 0.2447;
    l_2_h_hor = 3.398;
    l_2_h_vert = 4.085;
}

GenericAdapterTest::~GenericAdapterTest() {
}

void GenericAdapterTest::setUp() {
}

void GenericAdapterTest::tearDown() {
}

void GenericAdapterTest::testAdaptCells1() {
//    vector<Cell>::iterator itCells;
//        
//    vector<Cell> result = genericAdapter1->adaptCells(cells);
//    
//    int i = 0;
//    for(itCells = result.begin(); itCells != result.end(); itCells++, i++) {
//        if((itCells->equals(cells[i])) == true) {
//            CPPUNIT_ASSERT(false);
//        }
//    }
}

void GenericAdapterTest::testAdaptCells2() {
//    vector<Cell>::iterator itCells;
//        
//    vector<Cell> result = genericAdapter2->adaptCells(cells);
//    
//    int i = 0;
//    for(itCells = result.begin(); itCells != result.end(); itCells++, i++) {
//        if((itCells->equals(cells[i])) == true) {
//            CPPUNIT_ASSERT(false);
//        }
//    }
}

void GenericAdapterTest::testAdaptCells3() {
//    vector<Cell>::iterator itResults;
//        
//    vector<Cell> result = genericAdapter3->adaptCells(cells);
//       
//    int i = 0;
//    for(itResults = result.begin(); itResults != result.end(); itResults++, i++) {
//        if(itResults->equals(cells[i]) == true) {
//            CPPUNIT_ASSERT(false);
//        }
//        double x = fabs(cells[i].leftUpper.x - (h_2_l_hor * itResults->leftUpper.x));
//        if(x > EPSILON) {
//            CPPUNIT_ASSERT(false);
//        }
//        if(fabs(cells[i].leftUpper.y - h_2_l_vert * itResults->leftUpper.y) > EPSILON) {
//            CPPUNIT_ASSERT(false);
//        }
//        if(fabs(cells[i].rightBottom.x - h_2_l_hor * itResults->rightBottom.x) > EPSILON) {
//            CPPUNIT_ASSERT(false);
//        }
//        if(fabs(cells[i].rightBottom.y - h_2_l_vert * itResults->rightBottom.y) > EPSILON) {
//            CPPUNIT_ASSERT(false);
//        }
//    }
}

void GenericAdapterTest::testAdaptCells4() {
//    vector<Cell>::iterator itCells;
//        
//    vector<Cell> result = genericAdapter4->adaptCells(cells);
//    
//    int i = 0;
//    for(itCells = result.begin(); itCells != result.end(); itCells++, i++) {
//        if(itCells->equals(cells[i]) == true) {
//            CPPUNIT_ASSERT(false);
//        }
//        if(fabs(cells[i].leftUpper.x - l_2_h_hor * itCells->leftUpper.x) > EPSILON) {
//            CPPUNIT_ASSERT(false);
//        }
//        if(fabs(cells[i].leftUpper.y - l_2_h_hor * itCells->leftUpper.y) > EPSILON) {
//            CPPUNIT_ASSERT(false);
//        }
//        if(fabs(cells[i].rightBottom.x - l_2_h_hor * itCells->rightBottom.x) > EPSILON) {
//            CPPUNIT_ASSERT(false);
//        }
//        if(fabs(cells[i].rightBottom.y - l_2_h_hor * itCells->rightBottom.y) > EPSILON) {
//            CPPUNIT_ASSERT(false);
//        }
//    }
}

void GenericAdapterTest::testAdaptPoint() {
    vector<CvPoint> adaptedPoints;
    vector<Cell>::iterator itCells = cells.begin();
    
    adaptedPoints.push_back(genericAdapter3->adaptPoint(itCells->leftUpper));
    adaptedPoints.push_back(genericAdapter3->adaptPoint(itCells->rightBottom));
    
    double x1 = fabs(adaptedPoints[0].x - h_2_l_hor * cells[0].leftUpper.x);
    int apl = adaptedPoints[0].x;
    if (x1 > EPSILON) {
        CPPUNIT_ASSERT(false);
    }
    if(fabs(adaptedPoints[0].y - h_2_l_vert * cells[0].leftUpper.y) > EPSILON) {
        CPPUNIT_ASSERT(false);
    }
    double x = fabs(adaptedPoints[1].x - h_2_l_hor * cells[0].rightBottom.x);
    int ap1x = adaptedPoints[1].x;
    if(x > EPSILON) {
        CPPUNIT_ASSERT(false);
    }
    if(fabs(adaptedPoints[1].y - h_2_l_vert * cells[0].rightBottom.y) > EPSILON) {
        CPPUNIT_ASSERT(false);
    }
}

void GenericAdapterTest::testAdaptPoints() {
//    vector<CvPoint> points;
//    GenericAdapter genericAdapter;
//    vector<CvPoint> result = genericAdapter.adaptPoints(points);
    if (true /*check result*/) {
        CPPUNIT_ASSERT(false);
    }
}

